import {addOutput} from '../outputs'

export type Button = {
    disable: boolean;
    type: string;
    name: string;
    title: string;
    url: string;
    order?: number;
}

export const MAX_ORDER = 60
export const MIN_ORDER = 40
export const DEFAULT_ORDER = 50


// order: 40-60, default value: 50. the smaller order will be ranked first.
export function addLink(name: string, url: string, order = DEFAULT_ORDER): void {
    if (order < MIN_ORDER || order > MAX_ORDER){
        throw new Error(`order must be between ${MIN_ORDER} and ${MAX_ORDER}`)
    }
    const button :Button={
        disable: false,
        type: "LINK",
        name: name,
        title: name,
        url: url,
        order: order,
    }
    addOutput("BUTTONS=[" + JSON.stringify(button) + "]");
}